fr = open("result.txt","r",encoding = "utf-8")
fw = open("crf_format.txt","w",encoding = "utf-8")

f1 = fr.readlines()
for line in f1:
    if line == "\n":
        fw.write('\n')
        continue
    line = line.strip().split()
    if line[-1] == "O/en":
        for i in range(len(line)-1):
            line[i] = line[i].split("/")
            fw.write(line[i][0]+" "+line[i][1]+" "+"O"+"\n")
            
    elif line[-1] == "S/en":
        if len(line) == 2:
            line[0] = line[0].split("/")
            fw.write(line[0][0]+" "+line[0][1]+" "+"tmS"+"\n")
        elif len(line) == 3:
            for i in range(len(line)-1):
                line[i] = line[i].split("/")
                if i == 0:
                    fw.write(line[i][0]+" "+line[i][1]+" "+"tmB"+"\n")
                elif i == 1:
                    fw.write(line[i][0]+" "+line[i][1]+" "+"tmE"+"\n")
        else:
            for i in range(len(line)-1):
                line[i] = line[i].split("/")
                if i == 0:
                    fw.write(line[i][0]+" "+line[i][1]+" "+"tmB"+"\n")
                elif i == len(line)-2:
                    fw.write(line[i][0]+" "+line[i][1]+" "+"tmE"+"\n")
                else:
                    fw.write(line[i][0]+" "+line[i][1]+" "+"tmI"+"\n")
        
fr.close()
fw.close()
print("ok")
